home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3006 / 3006.xpi / chrome / dwhelper.jar / content / media-list-control.xml < prev    next >
Extensible Markup Language  |  2010-01-15  |  5KB  |  180 lines

  1. <?xml version="1.0"?>
  2. <!-- *****************************************************************************
  3.  *            Copyright (c) 2006-2009 Michel Gutierrez. All Rights Reserved.
  4.  ****************************************************************************** -->
  5. <!DOCTYPE bindings SYSTEM "chrome://dwhelper/locale/dwhelper.dtd" >
  6.  
  7. <bindings xmlns="http://www.mozilla.org/xbl"
  8.     xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  9.     xmlns:html="http://www.w3.org/1999/xhtml"
  10.     xmlns:xbl="http://www.mozilla.org/xbl">
  11.  
  12.     <binding id="MediaListControl" extends="widgets.xml#widget">
  13.  
  14.         <xbl:content xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  15.             <hbox flex="1">
  16.                 <spacer flex="1"/>
  17.                 <button anonid="xWatchBut" 
  18.                     oncommand="this.parentNode.parentNode.watch()"
  19.                     label="&button.medialist.watch;"/>
  20.                 <button anonid="xDownloadBut"
  21.                     oncommand="this.parentNode.parentNode.download()"
  22.                     label="&button.medialist.download;"/>
  23.                 <PopupButton anonid="xMoreBut" label="&button.medialist.more;">
  24.                     <menuitem anonid="xSourceBut" 
  25.                         label="&button.medialist.go-source;" 
  26.                         oncommand="this.parentNode.parentNode.parentNode.goSource()"/>
  27.                     <menuitem anonid="xRemoveBut" 
  28.                         label="&button.medialist.remove;" 
  29.                         oncommand="this.parentNode.parentNode.parentNode.remove()"/>
  30.                 </PopupButton>
  31.                 <spacer flex="1"/>
  32.             </hbox>
  33.             <children style="display: none;"/>
  34.         </xbl:content>
  35.  
  36.         <implementation>
  37.  
  38.             <constructor>
  39.                 <![CDATA[
  40. this.setSelection(null,[]);
  41. this.core=Components.classes["@downloadhelper.net/core;1"].
  42.     getService(Components.interfaces.dhICore);
  43.                 ]]>
  44.             </constructor>
  45.                         
  46.             <method name="setSelection">
  47.                 <parameter name="media"/>
  48.                 <parameter name="medias"/>
  49.                 <body>
  50.                 <![CDATA[
  51. this.dlMgr=Components.classes["@downloadhelper.net/download-manager;1"]
  52.     .getService(Components.interfaces.dhIDownloadMgr);
  53. this.media=media;
  54. this.medias=medias;
  55. var mediaButs=["xWatchBut","xMoreBut","xSourceBut"];
  56. for(var but in mediaButs) {
  57.     var mediaBut=mediaButs[but];
  58.     if(media==null)
  59.         this[mediaBut].setAttribute("hidden","true");
  60.     else
  61.         this[mediaBut].setAttribute("hidden","false");
  62. }
  63. mediaButs=["xDownloadBut","xRemoveBut"];
  64. for(var but in mediaButs) {
  65.     var mediaBut=mediaButs[but];
  66.     if(medias==null || medias.length==0)
  67.         this[mediaBut].setAttribute("hidden","true");
  68.     else
  69.         this[mediaBut].setAttribute("hidden","false");
  70. }
  71.                 ]]>
  72.                 </body>
  73.             </method>
  74.  
  75.             <method name="setView">
  76.                 <parameter name="xView"/>
  77.                 <body>
  78.                 <![CDATA[
  79. this.xView=xView;
  80.                 ]]>
  81.                 </body>
  82.             </method>
  83.  
  84.             <method name="setList">
  85.                 <parameter name="xList"/>
  86.                 <body>
  87.                 <![CDATA[
  88. this.xList=xList;
  89.                 ]]>
  90.                 </body>
  91.             </method>
  92.  
  93.                         
  94.             <method name="watch">
  95.                 <body>
  96.                 <![CDATA[
  97. if(this.media!=null) {
  98.  
  99.     var ds=this.mediaListMgr.getDataSource();
  100.     var url=this.util.getPropertyValueSS(ds,this.media,this.NS+"url");
  101.     var type=this.util.getPropertyValueSS(ds,this.media,this.NS+"type");
  102.     var pageurl=this.util.getPropertyValueSS(ds,this.media,this.NS+"pageurl");
  103.     if(url!=null) {
  104.         try {
  105.         this.mediaListMgr.addCurrentURL(url);
  106.         } catch(e) {
  107.             dump("!!![media-list-control] watch: "+e+"\n");
  108.         }
  109.         url=url.replace(/^(?:https?:\/\/)?(.*)$/,"$1");
  110.         var fullurl="http://www.downloadhelper.net/watch.php?media="+escape(url)+"&type="+escape(type);
  111.         if(pageurl!=null)
  112.             fullurl+="&pageurl="+escape(pageurl);
  113.         this.xView.setAttribute("src",fullurl);
  114.     }
  115. }
  116.                 ]]>
  117.                 </body>
  118.             </method>
  119.  
  120.             <method name="goSource">
  121.                 <body>
  122.                 <![CDATA[
  123. var ds=this.mediaListMgr.getDataSource();
  124. var media=this.xList.getSelectedMedia();
  125. if(media!=null) {
  126.     var url=this.util.getPropertyValueSS(ds,media,this.NS+"pageurl");
  127.     if(url!=null) {
  128.         window.open(url,"dwhelper-video-source");
  129.     }
  130. }
  131.                 ]]>
  132.                 </body>
  133.             </method>
  134.  
  135.             <method name="download">
  136.                 <body>
  137.                 <![CDATA[
  138. try {
  139.     var ds=this.mediaListMgr.getDataSource();
  140.     var medias=this.xList.getSelectedMedias();
  141.     for(var i in medias) {
  142.         var media=medias[i];
  143.         var uri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURI);
  144.         uri.spec = this.util.getPropertyValueRS(ds,media,this.NS+"url");
  145.         var filename = this.util.getPropertyValueRS(ds,media,this.NS+"filename");
  146.         var referer = this.util.getPropertyValueRS(ds,media,this.NS+"referer");
  147.         var desc=Components.classes["@mozilla.org/properties;1"].
  148.             createInstance(Components.interfaces.nsIProperties);
  149.         Util.setPropsString(desc,"media-url",uri.spec);
  150.         Util.setPropsString(desc,"page-url",referer);
  151.         Util.setPropsString(desc,"label",filename);
  152.         Util.setPropsString(desc,"file-name",filename);
  153.         this.core.quickProcess(desc);
  154.     }
  155. } catch(e) {}
  156.                 ]]>
  157.                 </body>
  158.             </method>
  159.  
  160.             <method name="remove">
  161.                 <body>
  162.                 <![CDATA[
  163. try {
  164.     var medias=this.xList.getSelectedMedias();
  165.     for(var i in medias) {
  166.         var media=medias[i];
  167.         this.mediaListMgr.removeFromList(this.xList.list,media.Value);
  168.     }
  169. } catch(e) {
  170. }
  171.                 ]]>
  172.                 </body>
  173.             </method>
  174.             
  175.         </implementation>
  176.                 
  177.     </binding>
  178.  
  179. </bindings>
  180.